<?php
function trip_homepage() {
  global $language;
  $profile_type = substr($language->language, 0, 2);

  $query = db_select("node", "n");
  $query->fields('n', array('nid', 'title', 'created', 'uid'));
  $query->addField("body", "body_value", "detail");
  $query->addField("fm", "uri");
  $query->addField("name", "field_name_value", "exp_name");
  $query->leftJoin('profile', 'up', "up.uid = n.uid AND up.type = '$profile_type'");
  $query->leftJoin("field_data_field_name", "name", "name.entity_id = up.pid AND name.deleted = 0");
  $query->leftJoin("field_data_field_exp_address", "ads", "ads.entity_id = n.nid AND ads.deleted = 0");
  $query->leftJoin("field_data_field_exp_photos", "photos", "photos.entity_id = n.nid AND photos.deleted = 0 AND photos.delta = 0");
  $query->leftJoin('file_managed', 'fm', 'fm.fid = photos.field_exp_photos_fid');
  $query->leftJoin("field_data_body", "body", "body.entity_id = n.nid AND body.deleted = 0");
  $query->leftJoin("field_data_field_approval", "approval", "approval.entity_id = n.nid AND approval.deleted = 0");
  $query->condition("approval.field_approval_value", 3);
  $query->condition("n.type", "exp_basic");
  $query->condition("n.uid", 0, ">");
  $query->orderBy("n.created", "DESC");
  $query->range(0, 6);
  $result = $query->execute();
  $exp_list = array();
  while ($record = $result->fetchObject()) {
    $exp_list[] = $record;
  }
  $item_name = 'Search Keywords';
  if($profile_type != 'en') {
      $item_name = '搜索关键字';
  }
  $categorys = taxonomy_get_term_by_name($item_name);
  $category = array_pop($categorys);
  $items = taxonomy_get_children($category->tid);
  $items['data'] = $exp_list;
  $items['keywords'] = $items;
  return theme("trip_homepage", array('items' => $items));
}